﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace TheQuest
{
    class Player : Mover
    {
        private Weapon equippedWeapon;
        private int hitPoints;
        public int HitPoints { get { return hitPoints; } }

        private List<Weapon> inventory = new List<Weapon>();

        public List<string> Weapons
        {
        get {
            List<string> names = new List<string>();
            foreach (Weapon Weapon in inventory)
		        names.Add(Weapon.Name);
            return names;
            }
        }

        public Player(Game game, Point location) : base(game, location)
        {
            hitPoints = 10;
        }

        public void Hit(int maxDamage, Random random)
        {
            hitPoints -= random.Next(1, maxDamage);
        }

        public void IncreaseHealth(int health, Random random)
        {
            hitPoints += random.Next(1, health);
        }

        public void Equip(string weaponName)
        {
            foreach (Weapon weapon in inventory)
            {
                if (weapon.Name == weaponName)
                    equippedWeapon = weapon;
            }
        }

        public void Move(Direction direction)
        {
            base.location = Move(direction, game.Boundaries);
            if (!game.WeaponInRoom.PickedUp)
            // see if the weapon is nearby (within a single unit of distance), and if so, pick up the weapon and add it to the player's inventory.
            {
                if (Nearby(game.WeaponInRoom.Location, 1))
                {
                    game.WeaponInRoom.PickUpWeapon();
                    inventory.Add(game.WeaponInRoom);
                    if (equippedWeapon == null)
                    {
                        Equip(game.WeaponInRoom.Name);
                    }
                }
            }
        }

        public void Attack(Direction direction, Random random)
        {
            //If the player has nothing equipped then this method does nothing.
            if (equippedWeapon == null)
            {
                //figure out which weapon is equipped and call that weapon's Attack() method.
                equippedWeapon.Attack(direction, random);

                //If the weapon is a potion, then Attack() removes it from the inventory after the player drinks it.
                if (equippedWeapon is IPotion)
                {
                    inventory.Remove(equippedWeapon);
                }
            }
        }
    }
}
